/*
* created by Administrator on 2018/12/11
* 好的代码像粥一样,是得用时间和精力熬的。
*/
import Router from 'vue-router';
import login from '../components/login';
import reg from '../components/reg';
import details from '../components/details';
import aa from '../components/aa';

export const router = new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component: login,
    },
    {
      path: '/reg',
      name: 'reg',
      component: reg,
    },
    {
      path: '/details',
      name: 'details',
      component: details,
      meta: {
        requireLogin: true,
      },
      children: [
        {
          path: 'details_a',
          name: 'details_a',
          component: aa,
        },
      ],
    },
  ],
});
const auth = false;
router.beforeEach((to, from, next) => {
  if (to.matched.some((value => value.meta.requireLogin))) {
    if (auth) {
      next();
    } else {
      next('/login');
    }
  } else {
    next();
  }
});
